//
//  TTSizeGuidePlayerViewController.m
//  TaoTuo
//
//  Created by admin on 2020/1/5.
//  Copyright © 2020 admin. All rights reserved.
//

#import "TTSizeGuidePlayerViewController.h"
#import "LLPlayerContainerView.h"
#import "AppDelegate.h"

@interface TTSizeGuidePlayerViewController ()

@property (nonatomic, strong) LLPlayerContainerView *playerView;
@property (nonatomic, copy) NSString *videoUrlString;
@property (nonatomic, strong) UIImage *shadowImage;
@property (nonatomic, assign) ScreenStatus status;

@end

@implementation TTSizeGuidePlayerViewController

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    AppDelegate *delegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
    delegate.allowRotate = YES;
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    AppDelegate *delegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
    delegate.allowRotate = NO;
    
}

- (instancetype)initWithVideoUrlString:(NSString *)urlString
{
    self = [super init];
    if (self) {
        self.videoUrlString = urlString;
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.edgesForExtendedLayout = UIRectEdgeTop;
    self.fd_prefersNavigationBarHidden = YES;
    // 播放视频
    self.playerView = [[LLPlayerContainerView alloc] initWithFrame:self.view.bounds superView:self.view inViewController:self];
    self.playerView.videoUrlString = self.videoUrlString;
    self.status = VerticalPlayStatus;
    
    
    UIButton *backBtn = [UIButton createButtonWithImage:[UIImage imageNamed:@"white_navback"] target:self action:@selector(backAction)];
    backBtn.frame = CGRectMake(0, 0, 44, StatusBarAndNavBar_Height);
    [self.playerView addSubview:backBtn];
    
    @weakify(self)
    self.playerView.screenStatusBlock = ^(ScreenStatus screenStatus) {
        @strongify(self)
        self.status = screenStatus;
        backBtn.hidden = screenStatus == LandscapePlayStatus;
    };
    self.playerView.operationViewIsHiddenBlock = ^(BOOL isHidden) {
        @strongify(self)
        if (self.status == VerticalPlayStatus) {
            backBtn.hidden = isHidden;
        }
    };

}

- (void)dealloc
{
    [self.playerView remoAllOberver];
}


@end
